package aierjun.action;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import aierjun.bean.UserBean;
import aierjun.dao.UserDao;
import aierjun.service.UserService;
import aierjun.utils.JsonOutUtils;


public class UserController implements Controller {
	private UserService UserService;

	@Override
	public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception {
		UserBean userBean=new UserBean();
		System.out.println("controller");
		if (!req.getParameter("uname").equals("")) {
			userBean.setUname(req.getParameter("uname"));
			int service=UserService.add(userBean);
			if (service>0) {
				System.out.println(service+"      23333333333333333    ");
				JsonOutUtils.JsonOut(resp, service);
			}else {
				System.out.println(service+"         55555555555555555       ");
				String string="error";
				JsonOutUtils.JsonOut(resp, service,string);
			}
		}else {
			int code=-1;
			String string="null";
			JsonOutUtils.JsonOut(resp, code,string);
		}
		return null;
	}
	public UserService getUserService() {
		return UserService;
	}

	public void setUserService(UserService userService) {
		UserService = userService;
	}
}
